package com.huaguoguo.cyg.spider.processor;

import cn.hutool.json.JSONUtil;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.processor.PageProcessor;

import java.util.HashMap;
import java.util.Map;

/**
 * 所有PageProcessor的基类
 * @author Administrator
 */
public abstract class BasePageProcessor implements PageProcessor {

    protected Site site = Site.me()
            .setSleepTime(1000)
            .setCycleRetryTimes(3)
            .addHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3")
            .addHeader("Cookie","SUB=_2AkMpf0drf8NxqwJRmP4QzG_gbIV_wwDEieKfI7awJRMxHRl-yT9jqhUrtRB6Av9phAZqvqJd-7L5ZkMfk2XMyWtjOJnA; SUBP=0033WrSXqPxfM72-Ws9jqgMF55529P9D9WhQDxzjlWl.6LH2GPIRV9Kf; SINAGLOBAL=3853482290364.5806.1579403358006; _s_tentry=-; Apache=8465125576025.445.1579501736841; ULV=1579501736924:3:3:3:8465125576025.445.1579501736841:1579404409768; YF-V5-G0=f0aacce81fff76e1515ae68ac76a20c3; YF-Page-G0=0acee381afd48776ab7a56bd67c2e7ac|1579503554|1579503515")
            .setUserAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36");
    @Override
    public Site getSite() {
        return site;
    }

    protected Map<String, Object> data = new HashMap<>();

    public BasePageProcessor addData(String key,Object value){
        data.put(key, value);
        return this;
    }

    /**
     * 构建一个完整的请求链接
     * @return
     */
    public abstract String buildRequestUrl();
}
